package com.itheima.d3_UDP_Multiple;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

/**
 * 怎么不断收呢
 */
public class Server {

    public static void main(String[] args) throws Exception {
        //1. 创建接受方
        DatagramSocket socket_receiver = new DatagramSocket(999);

        //2. 定义盘子
        byte[] bytes = new byte[1024 * 64];
        DatagramPacket packet = new DatagramPacket(bytes,bytes.length);

        while (true) {
            //3. 收数据
            socket_receiver.receive(packet);
            String client_address = packet.getSocketAddress().toString();
            int client_port = packet.getPort();
            String rs = new String(bytes,0,packet.getLength());
            System.out.println(rs);

            System.out.println("发送方IP:"+client_address);
            System.out.println("发送方端口:"+client_port);
        }
    }
}
